package com.maltys.greedy;

import java.util.Arrays;

/**
 * @author malty
 * @link <a href="https://leetcode.cn/problems/assign-cookies/description/">分发饼干</a>
 */
public class AssignCookies {
    public int findContentChildren(int[] g, int[] s) {
        Arrays.sort(g);
        Arrays.sort(s);
        int cnt = 0;
        int idx = 0;
        for (int i = 0; i < g.length; i++) {
            while (idx < s.length && s[idx] < g[i]) {
                idx++;
            }
            if (idx < s.length) {
                idx++;
                cnt++;
            }
        }
        return cnt;
    }

    public static void main(String[] args) {
        AssignCookies assignCookies = new AssignCookies();
        int contentChildren = assignCookies.findContentChildren(new int[]{1, 2, 3}, new int[]{1, 1});
        System.out.println(contentChildren);
    }
}
